package com.wyth.lottery.activity;

import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;

import com.wyth.lottery.R;
import com.wyth.lottery.base.BaseActivity;
import com.wyth.lottery.base.BaseFragment;
import com.wyth.lottery.fragment.BZFragment;
import com.wyth.lottery.fragment.DTFragment;
import com.wyth.lottery.fragment.HeZhiFragment;
import com.wyth.lottery.fragment.ThreeLianFragment;
import com.wyth.lottery.fragment.ThreeNoTongFragment;
import com.wyth.lottery.fragment.ThreeTongFragment;
import com.wyth.lottery.fragment.TwoNoTongFragment;
import com.wyth.lottery.fragment.TwoTongFragment;
import com.wyth.lottery.utils.MyApplication;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class QThreeSelectActivity extends BaseActivity {

    @BindView(R.id.tv_hezhi)
    TextView tvHezhi;
    @BindView(R.id.tv_2tonghao)
    TextView tv2tonghao;
    @BindView(R.id.tv_3tonghao)
    TextView tv3tonghao;
    @BindView(R.id.tv_2notonghao)
    TextView tv2notonghao;
    @BindView(R.id.tv_3notonghao)
    TextView tv3notonghao;
    @BindView(R.id.tv_3lianhao)
    TextView tv3lianhao;
    @BindView(R.id.iv_hezhi)
    ImageView ivHezhi;
    @BindView(R.id.iv_2tonghao)
    ImageView iv2tonghao;
    @BindView(R.id.iv_3tonghao)
    ImageView iv3tonghao;
    @BindView(R.id.iv_2notonghao)
    ImageView iv2notonghao;
    @BindView(R.id.iv_3notonghao)
    ImageView iv3notonghao;
    @BindView(R.id.iv_3lianhao)
    ImageView iv3lianhao;
    @BindView(R.id.fl_framelayout)
    FrameLayout flFramelayout;
    @Override
    protected int getContentID() {
        return R.layout.activity_qthree_select;
    }

    @Override
    protected void initView() {

        switch (getIntent().getIntExtra("int_data", 0)){

            case 0:
                initTextView(tvHezhi,ivHezhi,new HeZhiFragment());
                break;
            case 1:
                initTextView(tv2tonghao,iv2tonghao,new TwoTongFragment());
                break;
            case 2:
                initTextView(tv3tonghao,iv3tonghao,new ThreeTongFragment());
                break;
            case 3:
                initTextView(tv2notonghao,iv2notonghao,new TwoNoTongFragment());
                break;
            case 4:
                initTextView(tv3notonghao,iv3notonghao,new ThreeNoTongFragment());
                break;
            case 5:
                initTextView(tv3lianhao,iv3lianhao,new ThreeLianFragment());
                break;
        }
    }

    private void initTextView(TextView textView, ImageView imageView, BaseFragment fragment) {
        initTextSize(44);
        textView.setTextSize(px2dip(MyApplication.getContext(), 66));
        initImageVisibily(View.INVISIBLE);
        imageView.setVisibility(View.VISIBLE);
        getSupportFragmentManager()
                .beginTransaction()
                .replace(R.id.fl_framelayout,fragment)
                .commit();
    }


    private void initImageVisibily(int invisible) {
        ivHezhi.setVisibility(invisible);
        iv2tonghao.setVisibility(invisible);
        iv3tonghao.setVisibility(invisible);
        iv2notonghao.setVisibility(invisible);
        iv3notonghao.setVisibility(invisible);
        iv3lianhao.setVisibility(invisible);
    }


    @Override
    protected void initDate() {

    }

    @OnClick({R.id.tv_hezhi, R.id.tv_2tonghao, R.id.tv_3tonghao, R.id.tv_2notonghao, R.id.tv_3notonghao, R.id.tv_3lianhao})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.tv_hezhi:
                initTextView(tvHezhi,ivHezhi,new HeZhiFragment());
                break;
            case R.id.tv_2tonghao:
                initTextView(tv2tonghao,iv2tonghao,new TwoTongFragment());
                break;
            case R.id.tv_3tonghao:
                initTextView(tv3tonghao,iv3tonghao,new ThreeTongFragment());
                break;
            case R.id.tv_2notonghao:
                initTextView(tv2notonghao,iv2notonghao,new TwoNoTongFragment());
                break;
            case R.id.tv_3notonghao:
                initTextView(tv3notonghao,iv3notonghao,new ThreeNoTongFragment());
                break;
            case R.id.tv_3lianhao:
                initTextView(tv3lianhao,iv3lianhao,new ThreeLianFragment());
                break;
        }
    }

    public static int px2dip(Context context, float pxValue) {
        final float scale = context.getResources().getDisplayMetrics().density;
        return (int) (pxValue / scale + 0.5f);
    }
    private void initTextSize(float textsize) {
        tvHezhi.setTextSize(px2dip(MyApplication.getContext(), textsize));
        tv2tonghao.setTextSize(px2dip(MyApplication.getContext(), textsize));
        tv2notonghao.setTextSize(px2dip(MyApplication.getContext(), textsize));
        tv3tonghao.setTextSize(px2dip(MyApplication.getContext(), textsize));
        tv3notonghao.setTextSize(px2dip(MyApplication.getContext(), textsize));
        tv3lianhao.setTextSize(px2dip(MyApplication.getContext(), textsize));
    }
}
